<?php
$this->breadcrumbs = array(
    '主题管理' => array('/manage/topic/manage'),
    '主题关联管理' => array('/manage/topicext/manage?id='.$model->id),
    $type ==TopicExt::TYPE_TASK? '关联采集任务':'关联视频'
);
?>


<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'search-form',
    'type' => 'search',
    'method' => 'GET',
    'htmlOptions' => array('class' => 'navbar-search pull-left', 'style' => 'margin:0;width:100%;'),
));
if ($form instanceof TbActiveForm) {

}
?>
<div class="submenu">
    <div class="row">
        <div class="col-xs-5">
            <?php
            echo $form->textFieldRow($model, 'searchKey');
            ?>
        </div>
        <?php
        echo $type == TopicExt::TYPE_VIDEO?CHtml::tag('div', ['class' => 'col-xs-5'],$form->dropDownList($model, 'taskId', Task::getOptions('tasks', array('' => '===采集任务===')), array('class' => 'form-control', 'data-select' => 'picker', 'data-live-search' => 'true'))):'';
        ?>
        <div class="col-xs-1">
            <button class="btn btn-primary" style="width:100%;" type="submit" name="yt0"><i class="fa fa-search"></i>
            </button>
        </div>


    </div>
</div>
<?php
$this->endWidget();
?>


<div>
    <?php
    $columns = $model->getColumns($type);
    $this->widget('bootstrap.widgets.TbGridView', array(
        'id' => 'model-grid',
        'ajaxVar' => null,
        'type' => array(),
        'enableSorting' => true,
        'dataProvider' => TopicExt::getExtDb($model,$type,false),
        'columns' => $columns,
    ));
    ?>
</div>
<script type="text/javascript">
    $(function ($) {

        $(document).on('click', 'a.add', function () {
            var th = this;
            var afterDelete = function () {
            };
            var type = $(this).attr('type');
            var id = '';
            $.fn.yiiGridView.update('model-grid', {
                type: 'GET',
                url: $(this).attr('href'),
                ajaxUpdate: false,
                success: function (data) {
                    if (data == 'Success') {
                        $.fn.yiiGridView.update('model-grid');
                        alert('success');
                    } else {
                        alert(data);
                    }
                    afterDelete(th, true, data);
                },
                error: function (XHR) {
                    return afterDelete(th, false, XHR);
                }
            });
            return false;
        });
        $(document).on('click', 'a.muiltyAdd', function () {
            var th = this;
            var data = {
                'extids':[],
                'sort':'up'
            };
            data.sort = $(this).attr('sort');
            var videos = $('.video').each(function () {
                var isChecked = $(this).is(':checked');
                if(isChecked)
                {
                    data.extids.push($(this).attr('extid'));
                }

            });
            var afterDelete = function () {
            };
            $.fn.yiiGridView.update('model-grid', {
                type: 'Post',
                url: $(this).attr('href'),
                data:JSON.stringify(data),
                ajaxUpdate: false,
                success: function (data) {
                    if (data == 'Success') {
                        $.fn.yiiGridView.update('model-grid');
                        alert('success');
                    } else {
                        alert(data);
                    }
                    afterDelete(th, true, data);
                },
                error: function (XHR) {
                    return afterDelete(th, false, XHR);
                }
            });
            return false;
        });


    });
</script>
